package com.his.his_system.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.his.his_system.common.exception.PasswordBadException;
import com.his.his_system.common.util.ResultAdvice;
import com.his.his_system.controller.VisitController.Query;
import com.his.his_system.domain.DzmHisDoctor;
import com.his.his_system.domain.DzmHisMember;
import com.his.his_system.service.DzmHisMemberService;
import com.his.his_system.vo.DoctorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/his/sys/member/")
@RestController
@ResponseBody
public class MemberController {

    @Autowired
    DzmHisMemberService service;


    @PostMapping("modify")
    public ResultAdvice moidify(@RequestBody DzmHisMember param) {
        boolean update = service.updateById(param);
        return ResultAdvice.success(update);
    }

    /**
     * 获取被禁用的人数
     * @return
     */
    @GetMapping("disable_status")
    public ResultAdvice disableStatus(){
        QueryWrapper<DzmHisMember> qr = new QueryWrapper<DzmHisMember>().select("status").eq("status",2);
        return ResultAdvice.success(service.list(qr).size());
    }

    @GetMapping("user")
    public ResultAdvice getInfo() {
        return ResultAdvice.success(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    }

    @PostMapping("updatePswd")
    public ResultAdvice changePswd(@RequestBody DzmHisMember dzmHisMember) {
        try {
            boolean flag = service.changePswd(dzmHisMember);
        } catch (PasswordBadException e) {
            return ResultAdvice.fail("密码不正确");
        }

        return ResultAdvice.success("修改成功");
    }

}
